/*
 * ConfirmPayWayFragment.java
 * business
 *
 * Created by chentao on 2017/5/3.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.main.shoppingcart.cashier;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.base.BaseFragment;
import com.yidiandao.business.ui.main.shoppingcart.orderresult.OrderResultActivity;
import com.yidiandao.business.ui.url.UrlActivity;
import com.yidiandao.business.utils.TextRenderUtils;
import com.yidiandao.business.utils.UIUtils;

/**
 * 收银台-View
 */
public class CashierFragment extends BaseFragment implements CashierContract.View {

    private CashierContract.Presenter mPresenter;

    private Toolbar mToolbar;

    private TextView mTvMoney;

    private RelativeLayout mKuaiqianPay;

    public static CashierFragment getInstance() {
        CashierFragment fragment = new CashierFragment();
        return fragment;
    }

    @Override
    public void setPresenter(CashierContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return CashierFragment.class.getSimpleName();
    }

    @Override
    public void showToast(String text) {
        UIUtils.showToast(text);
    }

    @Override
    protected void initViews() {
        mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
        mTvMoney = (TextView) mRootView.findViewById(R.id.tv_money);
        mKuaiqianPay = (RelativeLayout) mRootView.findViewById(R.id.kuaiqian_pay);

        mPresenter.start();
        initListeners();
    }

    private void initListeners() {
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.checkAllOnlinePay();
            }
        });

        mKuaiqianPay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 快钱支付
                mPresenter.kuaiQianPay();
            }
        });
    }

    @Override
    public void toOrderResultActivity(String orderPayId) {
        OrderResultActivity.actionStart(mActivity, orderPayId, null);
    }

    @Override
    public void setTotalMoney(String totalMoney) {
        mTvMoney.setText(TextRenderUtils.getBeautyPrice(totalMoney, null, UIUtils.dp2px(15), UIUtils.dp2px(11)));
    }

    @Override
    public void toKuaiQianPayActivity(String orderPayId, String url) {
        UrlActivity.actionStartForOnlinePay(mActivity, url, orderPayId, true);
        mActivity.finish();
    }

    @Override
    public void finishActivity() {
        mActivity.finish();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_cashier;
    }

    public void onBackPress() {
        mPresenter.checkAllOnlinePay();
    }
}
